import 'package:flutter_elf/model/user.dart';
import 'package:shared_preferences/shared_preferences.dart';

///SharedPreferences 本地存储
class LocalStorage {
  static SharedPreferences prefs;

  static init() async {
    prefs = await SharedPreferences.getInstance();
  }

  static Future<bool> save(String key, value) async {
    if (value is String) {
      return prefs.setString(key, value);
    } else if (value is int) {
    } else if (value is double) {
      return prefs.setDouble(key, value);
    } else if (value is bool) {
      return prefs.setBool(key, value);
    }
    return prefs.setStringList(key, value);
  }

  static Future<bool> saveBool(String key, bool value) async {
    return prefs.setBool(key, value);
  }

  static dynamic get(String key) {
    return prefs.get(key);
  }

  static User getUser(){
    return User.empty();
  }

  static bool getBool(String key) {
    return prefs.getBool(key);
  }

  static Future<bool> cleanAll() async {
    return prefs.clear();
  }

  static Future<bool> remove(String key) async {
    return prefs.remove(key);
  }
}
